$NG.AllReady(function (page, { useAction, useBeforeClick, useValuesChange, useClick, useUpdateRow, subscribe, useUpdateRows }) {
    const mstform = $NG.getCmpApi("p_form_fbjs_m")
    const dgrid1 = $NG.getCmpApi("p_form_fbjs_d1")
    const getHeadValue = (str)=>mstform.getItem(str).getValue()

    if(page.oType == 'add'){
        setDateNum()
        mstform.getItem("u_jsnd").setValue({
            label:new Date().getFullYear(),
            value:new Date().getFullYear()
        })
    }
    setHiddenTabs()
    useValuesChange(()=>{
        setDateNum()
    },"p_form_fbjs_m.u_fbhtmc")

    useValuesChange(()=>{
        console.log(`u_mxxz`,);
        setHiddenTabs()
    },"p_form_fbjs_m.u_mxxz")

    // function 找期数
    async function setDateNum(){
        const res = await $NG.execServer("SELECT",{sql:`select * from p_form_fbjs_m`})
        if(res.count == 0) return 
        const datas = JSON.parse(res.data)[0].extendObjects
        mstform.getItem("u_zqs").setValue(res.count + 1)
        
        const phid = getHeadValue("u_fbhtmc")
        if(!phid) return 
        const res1 = await $NG.execServer("SELECT",{sql:`select * from p_form_fbjs_m where u_fbhtmc = '${phid}'`})
        if(res.count == 0) return 
        const datas1 = JSON.parse(res1.data)[0].extendObjects
        mstform.getItem("u_jsqs").setValue(res1.count + 1)
    }

        function getCntCbInfoByPhid() {
        const phid = mstform.getItem("u_fbsqrjfbhtspbh").getValue()
        if (!phid) return
        $NG.execServer("getCntCbInfoByPhid", { phid }, (res) => {
            if (res.count == 0) return
            const data = JSON.parse(res.data)[0].extendObjects
            const arr = [
                {
                    key: "bill_no",
                    value: data.cnt_no,
                },
                {
                    key: "phid_pc",
                    value: {
                        label:data.phid_pc,
                        value:data.phid_pc_exname
                    }
                },
                {
                    key: "u_fbsmc",
                    value: {
                        label: data.jfdw_name,
                        value: data.jfdw_phid
                    }
                },
                {
                    key: "u_fbhtje",
                    value: data.user_fbhtje
                }
            ]
            setHeadValues(arr)
        })
    }

    function setHiddenTabs(){
        const tabs = $NG
            .getCompMap()
            .get("__Tabs__")[0]
            .getApi();
        tabs.updateItems((innerItems, activeKey) => {
            return [...innerItems.filter((item) => {
                switch((Number(getHeadValue("u_mxxz")) || 0)){
                    case 1:
                        console.log(`1111`,);
                        if(item.name == 'tabPanel_tabItem' || item.name == 'tabPanel_tabItem_1'){
                            return item
                        }
                        
                        break
                    case 2:
                        if(['tabPanel_tabItem_2','tabPanel_tabItem_3','tabPanel_tabItem_4','tabPanel_tabItem_5',].includes(item.name)){
                            return item
                        }
                        break
                    case 3:
                        if([
                            'tabPanel_tabItem_7',
                            'tabPanel_tabItem_8',
                            'tabPanel_tabItem_9',
                            'tabPanel_tabItem_10',
                            'tabPanel_tabItem_11',
                            'tabPanel_tabItem_12',
                            'tabPanel_tabItem_13',
                            
                        ].includes(item.name)){
                            return item
                        }
                        break
                    default:
                }
                if(['tabPanel_tabItem_14','tabPanel_tabItem_15','tabPanel_tabItem_16','tabPanel_tabItem_17',].includes(item.name)){
                    return item
                }
            })];
        });
                    tabs.setActiveKey("tabPanel_tabItem_17");
        
    }

     // 表头批量赋值
    function setHeadValues(arr) {
        arr.forEach(item => {
            console.log(`执行更新`, item);
            mstform.getItem(item.key)?.setValue(item.value)
        })
    }
})